home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / security-second.cgi.z / security-second.cgi
Encoding:
Text File  |  1997-07-30  |  10.5 KB  |  308 lines

  1. #!/usr/bin/perl5
  2. #
  3. # security-second.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: security-second.cgi,v 1.8 1997/04/17 23:46:22 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.security-start.cgi",10,10); }
  25.  
  26. $myname = "security-second.cgi";
  27. $passwd = "/etc/passwd";
  28. $temp = "task.tmp2";
  29. $dummy = "task.dummy";
  30. $action = "security-second.cgi?loop";
  31.  
  32. $it = "<td><font size=5><i>";
  33. $ni = "</i></font></td>";
  34.  
  35. &get_fields;
  36. &getOpenAccounts;
  37.  
  38. if ($ARGV[0] eq 'loop') { %vals = %fld;  }
  39. else { &readValues if $num_accounts > 0; }
  40.  
  41. if ($ARGV[0] eq loop) {
  42.     &writeFile;
  43.  
  44.     $go = "/tasks/security-third.cgi?s";
  45.     # printf("Location: %s%c%c",$go,10,10);
  46.     print "Content-type: text/html\n\n";
  47.     print "<HTML><HEAD>";
  48.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  49.     print "</HEAD><BODY></BODY></HTML>";
  50.     exit 0;
  51. }
  52.  
  53. &generic;
  54.  
  55. sub getOpenAccounts {
  56.     $open_root = 0;
  57.     $num_accounts = 0;
  58.     while (($name,$pw,$d1,$d2,$d3,$d4,$d5,$d6,$d7) = getpwent) {
  59.         if ($pw eq "") { 
  60.             $accounts{$name} = ""; 
  61.             $num_accounts++;
  62.         }
  63.     }
  64.     $open_root = 1 if defined($accounts{'root'});
  65. }
  66.  
  67. sub readValues {
  68.     open(IN,"< $temp");
  69.     while(<IN>) {
  70.         @items = split(/=/);
  71.         chop $items[1];
  72.         if (defined($accounts{$items[0]})) { $accounts{$items[0]} = $items[1]; }
  73.     }
  74.     close(IN);
  75. }
  76.  
  77. sub writeFile {
  78.     open(OUT,"> $temp");
  79.     if ($fld{'ALL'}) { # hack to close all accounts
  80.         foreach $arg (keys(%accounts)) {
  81.             if ($arg eq "root") {
  82.                 print OUT "$arg=$vals{'pw$arg'}\n" if ($vals{'pw$arg'} ne ""); 
  83.             }
  84.             else { print OUT "$arg=close\n"; }
  85.         }
  86.     }
  87.     else {
  88.         foreach $arg (keys(%vals)) {
  89.             $name = $arg;
  90.             if ($arg =~ /^pw/) { 
  91.                 $name =~ s/^pw//g;
  92.                 print OUT "$name=$vals{$arg}\n" if ($vals{$arg} ne ""); 
  93.             } elsif ($arg =~ /^cl/) { 
  94.                 $name =~ s/^cl//g;
  95.                 print OUT "$name=close\n";
  96.             }
  97.         }
  98.     }
  99.     close(OUT);
  100. }
  101.  
  102. sub generic {
  103.     print "Content-type: text/html\n\n";
  104.     print "<html><head><title>Security Setup (continued)</title>\n";
  105.  
  106.     if ($num_accounts == 0) { &print_simple; exit 0; }
  107.  
  108.     print "<script language=\"JavaScript\">\n<!--\n";
  109.  
  110.     # JavaScript
  111. print "function Next()  {
  112.     form = document.page2;
  113.     if (!testInput(form)) return;
  114.     setTimeout('form.submit()',0);
  115.     return;
  116. }
  117. function Previous()  {
  118.     setTimeout('window.location=\"/tasks/Tasks.security-start.cgi?s\"',0);
  119.     return;
  120. }
  121. function testInput(form) {
  122.     still_open = false;
  123. ";
  124.  
  125. # test root password if necessary
  126.     if ($open_root) { 
  127.     print "    if (form.pwroot.value == \"\") { 
  128.         password = prompt(\"\\nYou have not entered a root password. \\nThis severely compromises the security \\nof your machine.\\n\\nPlease enter a password for the root \\naccount:\",\"\"); 
  129.         while (true) {
  130.             if (password == null) return (false);   // Clicked \"Cancel\"
  131.             error = testPassword(password); 
  132.             if (!error) { form.pwroot.value = password; break; }
  133.             if (error == 1) password = prompt(\"\\nPasswords cannot contain the\\n\" + illegal + \" character.\\n\\nPlease enter a password for the \\nroot account:\",\"\"); 
  134.             if (error == 2) password = prompt(\"\\nPasswords cannot contain spaces.\\n\\nPlease enter a password for the \\nroot account:\",\"\"); 
  135.         }
  136.     }\n";
  137.     }
  138.  
  139.     print "    if (form.ALL.checked) return (true);\n";
  140.  
  141. # test each password
  142.     foreach $arg (keys %accounts) { 
  143.         next if $arg eq "root";
  144.         print "    error = testPassword(form.pw$arg.value); if (error == 1) { ",
  145.               "errorBox(form.pw$arg,\"The $arg password cannot contain \\n",
  146.               "the \" + illegal + \" character.\"); return (false); } ",
  147.               "if (error == 2) { errorBox(form.pw$arg,\"The $arg password ",
  148.               "cannot contain spaces.\"); ",
  149.               "return (false); } \n";
  150.         print "        if (form.pw$arg.value == \"\" && ",
  151.               "(!form.cl$arg.checked)) still_open = true;\n";
  152.     }
  153.     print "    if (still_open) { return confirm(\"\\nSome accounts have ",
  154.           "neither been closed nor given \\na password.  This will leave ",
  155.           "those accounts open \\nand your machine insecure.\\n\\n Are you ",
  156.           "sure this is what you want to do?\"); } \n";
  157.  
  158. print "    return (true);
  159. }
  160. function testPassword(word) {
  161.     loginChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  162.     if (word == \"\") return 0;
  163.     for(j = 0; j < loginChars.length; j++) {
  164.         c = loginChars.charAt(j);
  165.         if (word.indexOf(c, 0) != -1) { illegal = c; return 1; }
  166.     }
  167.     for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 2; }
  168.     return 0;
  169. }
  170. function errorBox (Ctrl, ErrorMessage) {
  171.     alert (ErrorMessage);  Ctrl.focus();  return;
  172. }\n";
  173.  
  174.     print "//-->\n";
  175.     print "</script></head>\n\n";
  176.  
  177.     print "<body bgcolor=\'a7b4ce\' background=/tasks/security-task.bg.gif>\n";
  178.  
  179.     print "<table width=100%>",
  180.           "<tr><th align=left><h1>Security Setup (continued)</h1></th>\n",
  181.           "<th align=right><a href=\"/newsplash.shtml\">",
  182.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  183.           "  <a href=\"Tasks.shtml\">",
  184.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  185.           "</tr></table>\n";
  186.  
  187.     printf("\n<form name=\"page2\" action=\"%s\" method=post>\n", $action);
  188.     
  189.     print "<center><table width=620>\n";
  190.  
  191.     print "<tr>$it Accounts: <br>$ni</tr>\n";
  192.     print "<tr><td>Remote users and applications are required to use an
  193.     account whenever they access the server. You can increase security
  194.     on the server by closing some or all of its accounts or by assigning
  195.     account passwords.
  196.     <br><br>
  197.     The list below contains all accounts on the server that are currently 
  198.     unprotected. To secure the server, enter a password or check the 
  199.     <var>Close</var> box for each account. You can close all accounts in 
  200.     one step by selecting the <var>Close all accounts</var> box. 
  201.     </td></tr></table>\n\n";
  202.  
  203.     print "<table width=320>\n";
  204.  
  205.     print "<tr><td align=center><input type=checkbox name=ALL ",
  206.           "value=1></td><td colspan=2><strong>Close all accounts</strong></td>",
  207.           "</tr><tr><td></td></tr>\n"; 
  208.  
  209.     print "<tr><th>Close?</th><th>Account name</th><th>Password</th></tr>\n";
  210.  
  211.     foreach $arg (keys %accounts) { 
  212.         if ($accounts{$arg} eq "close") { $checked = "checked"; $pw = ""; }
  213.         else { $checked = ""; $pw = $accounts{$arg}; }
  214.         if ($arg eq "root") {
  215.             print "<tr><td align=center></td><td> $arg</td><td align=center>",
  216.                   "<input type=text name=\"pw$arg\" value=\"$pw\" size=10>",
  217.                   "<br></td></tr>\n"; 
  218.             next;
  219.         }
  220.         print "<tr><td align=center><input type=checkbox name=cl$arg ",
  221.               "value=1 $checked></td><td> $arg</td><td align=center>",
  222.               "<input type=text name=\"pw$arg\" value=\"$pw\" size=10>",
  223.               "<br></td></tr>\n"; 
  224.     }
  225.  
  226.     print "<tr>$it $ni</tr>\n";
  227.     print "</table></center>\n\n";
  228.  
  229.     print '<MAP NAME="js_map1">',
  230.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
  231.     onMouseOver="window.status=\'\';return true">',
  232.     '</MAP>';
  233.     print "\n";
  234.     print '<MAP NAME="js_map2">',
  235.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()"
  236.     onMouseOver="window.status=\'\';return true">',
  237.     '</MAP>';
  238.     print "\n";
  239.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map2" align="right">';
  240.     print "\n";
  241.     print '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" align="right">';
  242.  
  243.     print "\n</form></body></html>";
  244. }
  245.  
  246. sub print_simple {
  247.     print "<script language=\"JavaScript\">\n<!--\n";
  248.  
  249.     # JavaScript
  250. print "function Next()  {
  251.     form = document.page2;
  252.     setTimeout('form.submit()',0);
  253.     return;
  254. }
  255. function Previous()  {
  256.     setTimeout('window.location=\"/tasks/Tasks.security-start.cgi?s\"',0);
  257.     return;
  258. }\n";
  259.  
  260.     print "//-->\n";
  261.     print "</script></head>\n\n";
  262.  
  263.     print "<body bgcolor=\'a7b4ce\' background=/tasks/security-task.bg.gif>\n";
  264.  
  265.     print "<table width=100%>",
  266.           "<tr><th align=left><h1>Security Setup (continued)</h1></th>\n",
  267.           "<th align=right><a href=\"/newsplash.shtml\">",
  268.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  269.           "  <a href=\"Tasks.shtml\">",
  270.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  271.           "</tr></table>\n";
  272.  
  273.     printf("\n<form name=\"page2\" action=\"%s\" method=post>\n", $action);
  274.     print "<input type=hidden name=dummy value=\"\">\n";
  275.     
  276.     print "<center><table width=620>\n";
  277.  
  278.     print "<tr>$it Accounts: <br>$ni</tr>\n";
  279.     print "<tr><td>This page allows you to secure the accounts on
  280.     your machine.  The list below contains all accounts which are currently 
  281.     unprotected.  </td></tr></table>\n\n";
  282.  
  283.     print "<br><br><br><table width=320>\n";
  284.  
  285.     print "<tr><td align=center><strong>No currently open accounts</strong>",
  286.           "</td></tr><tr><td><br><br></td></tr>\n"; 
  287.  
  288.     print "<tr>$it $ni</tr>\n";
  289.     print "</table></center>\n\n";
  290.  
  291.     print '<MAP NAME="js_map1">',
  292.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
  293.     onMouseOver="window.status=\'\';return true">',
  294.     '</MAP>';
  295.     print "\n";
  296.     print '<MAP NAME="js_map2">',
  297.     '    <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Next()"
  298.     onMouseOver="window.status=\'\';return true">',
  299.     '</MAP>';
  300.     print "\n";
  301.     print '<IMG SRC="/tasks/rightarrow.gif" BORDER=0 USEMAP="#js_map2" align="right">';
  302.     print "\n";
  303.     print '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" align="right">';
  304.  
  305.     print "\n</form></body></html>";
  306. }
  307.  
  308.